package gametest1;

//arr={19,28,37,46,50}用程序实现数组中元素值的交换，
//交换后的数组：arr={50,46,37,28,19}输出交换后的元素。
public class 反转 {
    public static void main(String[] args) {
        int[] arr = {19, 28, 37, 46, 50};
        printArray(arr);
        reverse(arr);

    }

    public static void reverse(int[] arr) {
        for (int start = 0, end = arr.length - 1; start <= end; start++, end--) {
            int temp = arr[start];
            arr[start] = arr[end];
            arr[end] = temp;
        }
    }

    //遍历数组
    //返回值类型和参数
    public static void printArray(int[] arr) {
        System.out.print("[");
        for (int i = 0; i < arr.length; i++) {
            if (i == arr.length - 1) {
                System.out.print(arr[i]);
            } else {
                System.out.print(arr[i] + ", ");
            }

        }
        System.out.print("]");
    }

}